package com.atguigu.gmall.product.controller;
import com.atguigu.entity.BaseCategoryView;
import com.atguigu.entity.BaseSaleAttr;
import com.atguigu.entity.SkuImage;
import com.atguigu.entity.SkuInfo;
import com.atguigu.gmall.product.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("api/product") //方便swgger2扫描接口
public class ProductApiContoller {
    @Autowired
    SkuImageService skuImageService;
    @Autowired
    SkuInfoService skuInfoService;
    @Autowired
    BaseCategoryViewService baseCategoryViewService;
    @Autowired
    SpuSaleAttrService spuSaleAttrService;
    @GetMapping("inner/getSkuInfo/{skuId}") //inner表示内部资源 只给微服务内部使用
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
            //根据SkuId查询该库存的商品信息
        return skuInfoService.getById(skuId);
    }
    @GetMapping("inner/getSkuImage/{skuId}")
    public List<SkuImage> getSkuImage(@PathVariable Long skuId){
        //根据skuId查询所有的Sku图片信息
        return skuImageService.list(new QueryWrapper<SkuImage>().eq("sku_id",skuId));
    }
    @GetMapping("inner/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable Long skuId){
        //价格需要单独查询
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }
    @GetMapping("inner/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id ){
        //根据 3级分类id查询 3级分类Id来自于前面查询到的SkuInfo
      return   baseCategoryViewService.getOne(new QueryWrapper<BaseCategoryView>().eq("category3_id",category3Id));
    }
    @GetMapping("inner/selectSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<BaseSaleAttr> selectSpuSaleAttrListCheckBySku(@PathVariable Long skuId,
                                                              @PathVariable Long spuId){
        return spuSaleAttrService.selectSpuSaleAttrListCheckBySku(skuId,spuId);
    }
    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable ("spuId") Long spuId){
        return spuSaleAttrService.getSkuValueIdsMap(spuId);
    }
}